package Domain.forumManager;

import java.util.Vector;

import objects.Frm;
import objects.Message;
import objects.Trd;
import objects.User;
import DB.DB;

public class ForumController {

	private DB _database;
	
	private UserManager userManager;
	private ForumsManager forumsManager;
	public ForumController(DB database)
	{
		
		this._database=database;
		
		this.userManager=new UserManager(_database);
		this.forumsManager=new ForumsManager(_database);
	}
	
	///////////////////////// HANDEL TO FRIEND MANAGER ///////////////////////////////////////////
	
	
	/**
	 * @return -1 if one of the users doesn't found , 1 if friend added
	 */
	public int addFreind(String nameOfUser,String friendToBeAdded)
	{
		return userManager.addFreind(nameOfUser, friendToBeAdded);
		// the user is register to the freind to be added list
	}
	/**
	 * 
	 * @param nameOfUser
	 * @param friendToBeRemoved
	 * @return @return 1 if friend removed ,-1 if user not found , -2 if userToBeRemoved is not 
	 * friend of nameOfUser
	 */
	public int removeFriend (String nameOfUser,String friendToBeRemoved) 
	{
			return userManager.removeFriend(nameOfUser, friendToBeRemoved);
			// the user is register to the freind to be added list
	}
	
	
	///////////////////////// HANDEL TO USER MANAGER ///////////////////////////////////////////
	
	
	
	
	public void addUser (User u)
	{
		this.userManager.addUser(u);
	}
	/**
	 * 
	 * @param nameOfUser the name of the user to be added
	 */
	public void createUser(String nameOfUser)
	{
		this.userManager.createUser(nameOfUser);
	}
	
	
	/**
	 * remove User by his/her name
	 * @param nameOfUser the name of the user
	 * #return 1 if the user removed 0 otherwish
	 */
	public int removeUser(String nameOfUser)
	{
		return this.userManager.removeUser(nameOfUser);
		
	}
	/**
	 * remove user from the database
	 * @param userToBeRemove the user to be removed 
	 */
	public void removeUser(User userToBeRemove)
	{
		this.userManager.removeUser(userToBeRemove);
	}
	

	
	/**
	 * for tests return the user by is name
	 * @param nameOfUser
	 * @return
	 */
	
	public User getUserByName(String nameOfUser)
	{
		return this.userManager.getUserByName(nameOfUser);
	}
	
	
	
	/**
	 * 
	 * @param nameOfUser
	 * @param type 1 for manager , 0 to default user
	 * @return -1 if user doesn't found 1 otherwise
	 */
	public int changeUserType(String nameOfUser,int type)
	{
		return this.userManager.changeUserType(nameOfUser, type);
	}
	public Vector<User> getAllUsers()
	{
		return this.userManager.getAllUsers();
	}
	public Vector<String> getAllUsersAsString()
	{
		return this.userManager.getAllUsersAsString();
	}
	/**
	 * 
	 * @param nameOfUser
	 * @return all the freinds of the user
	 */
	public Vector <User> getFriendsOfUser(String nameOfUser)
	{
		return userManager.getFriendsOfUser(nameOfUser);
	}
	
	/**
	 * 
	 * @param nameOfUser
	 * @return  1 if manager , 0 if default ,-1 if user not found -2 if problem unknown
	 */
	public int getTypeOfUser(String nameOfUser)
	{
		return this.userManager.getTypeOfUser(nameOfUser);
	}
	
	/////////////////////////HANDEL THE FORUMS MANGER ///////////////////////////////
	
	
	
	/**
	 * 
	 * @param nameOfForum
	 * @param nameOfUser
	 * @return -1 if can't find user , -2 if user is a default user ,-3 if problem unknown , 1 if forum added
	 */
	
	public int addForum (String nameOfForum,String nameOfUser)
	{
		return this.forumsManager.addForum(nameOfForum, nameOfUser);
	}
	/**
	 * 
	 * @param nameOfForum
	 * @param nameOfUser
	 * @param nameOfThread
	 * @return -1 if user not found ,-2 if user doesn't a manager ,-3 if forum doesn't exist
	 * 1 if thread added
	 */
	public int addThread (String nameOfForum,String nameOfUser,String nameOfThread)
	{
		return this.forumsManager.addThread(nameOfForum, nameOfUser, nameOfThread);
	}
	/**
	 * uncomplete need to send the announsment to all of the User Friends
	 * @param nameOfForum the name of the forum to add the message
	 * @param nameOfUser the name of the User that added the message
	 * @param nameOfThread the name of the thread to add the message
	 * @param msg the msg to be added
	 * @return the vector of the friend to send them the message
	 */
	public Vector <User> addMessage (String nameOfForum,String nameOfUser,String nameOfThread,String msg)
	{
	return forumsManager.addMessage(nameOfForum, nameOfUser, nameOfThread, msg);
		
	}
	

	
	
	/**
	 * 
	 * @param nameOfForum
	 * @param nameOfUser
	 * @param nameOfThread
	 * @param msg
	 * @return -5 if user not owner nor manager,-4 if fail to find user, /
	 * -3 if can't find forum ,-2 if thread doesn't found ,/ 
	 *return -1 if message doesn't found ,/
	 * return 1 if object remove
	 */
	public int removeMessage(String nameOfForum,String nameOfUser,String nameOfThread,String msg)
	{
		return this.forumsManager.removeMessage(nameOfForum, nameOfUser, nameOfThread, msg);
		
	}
	
	/**
	 * 
	 * @param nameOfUser
	 * @param nameOfForum
	 * @param nameOfThread
	 * @param titleOfMessage
	 * @param newcontent
	 * @return -2 if thread doesn't found , return -1 if msg doesn't found , -3 if user doesn't found
	 *  -4 if forum doesn't found ,-5 unkown problem,return ,-6 if user not owner or manager,1 on seccss  
	 */
	public int editMessage (String nameOfUser, String nameOfForum , String nameOfThread, String titleOfMessage,String newContent)
	{
		return this.forumsManager.editMessage(nameOfUser, nameOfForum, nameOfThread, titleOfMessage, newContent);
	}
	
	public Vector<Trd> getThreads(String nameOfForum)
	{
		
		return this.forumsManager.getThreads(nameOfForum);
	}
	public Vector<Message> getMessages(String nameOfForum, String nameOfThread)
	{
		return this.forumsManager.getMessages(nameOfForum, nameOfThread);
	}
	

	public Vector<Frm> getForums ()
	{
		return this.forumsManager.getForums();
	}

	
}
